package com.sls.web.manager.game.parser;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.sls.web.manager.game.pojo.xqt.XQTAccountTypeInfo;
import com.sls.web.manager.game.pojo.xqt.XQTChargetypeInfo;
import com.sls.web.manager.game.pojo.xqt.XQTChoosegem;
import com.sls.web.manager.game.pojo.xqt.XQTGameAreaInfo;
import com.sls.web.manager.game.pojo.xqt.XQTGameAreaServerInfo;
import com.sls.web.manager.game.pojo.xqt.XQTGameServer;
import com.sls.web.manager.game.pojo.xqt.XQTParvalueInfo;
import com.sls.web.manager.game.pojo.xqt.XQTTopInfo;

/**
 * 处理map中的内容,返回不同的对象
 * 
 * @author cx
 * 
 */
public class MapUtil {

	/**
	 * 获取产品面值信息
	 * 
	 * @param map
	 * @return
	 */
	public static List<XQTParvalueInfo> getParvalueListFromMap(
			Map<String, List<Object>> map) {
		List<XQTParvalueInfo> parvalueList = new ArrayList<XQTParvalueInfo>();
		List<Object> gametypes = map.get("gametype");
		List<Object> gametype1s = map.get("gametype1");
		String gametype = null;
		String gametype1 = null;
		if (gametypes != null && !gametypes.isEmpty()) {
			gametype = (String) gametypes.get(0);
		}
		if (gametype1s != null && !gametype1s.isEmpty()) {
			gametype1 = (String) gametype1s.get(0);
		}
		List<Object> parvalues = map.get("parvalue_s");
		XQTParvalueInfo info = null;
		if (parvalues != null && !parvalues.isEmpty()) {
			for (Object obj : parvalues) {
				if (obj instanceof XQTParvalueInfo) {
					XQTParvalueInfo parInfo = (XQTParvalueInfo) obj;
					List<XQTChargetypeInfo> chargeTypes = parInfo
							.getChargeTypes();
					List<XQTChoosegem> choosegemList = parInfo
							.getChoosegemList();
					if (chargeTypes != null
							&& !chargeTypes.isEmpty()
							&& (choosegemList == null || choosegemList
									.isEmpty())) {
						XQTChargetypeInfo chargeTypeInfo = chargeTypes.get(0);
						// for (XQTChargetypeInfo chargeTypeInfo : chargeTypes)
						// {
						info = new XQTParvalueInfo();
						info.setGametype(gametype);
						info.setGametype1(gametype1);
						info.setParvalueId(parInfo.getParvalueId());
						info.setParvalueName(parInfo.getParvalueName());
						info.setProductid(parInfo.getProductid());
						info.setSaleprice(parInfo.getSaleprice());
						info.setProductid1(parInfo.getProductid1());
						info.setSign(parInfo.getSign());
						info.setChargetypeId(chargeTypeInfo.getChargetypeId());
						info.setChargetypeName(chargeTypeInfo
								.getChargetypeName());
						info.setBuynumber_list(chargeTypeInfo
								.getBuynumber_list());
						info.setTbuynumber_list(chargeTypeInfo
								.getTbuynumber_list());
						info.setTbuynumbername(chargeTypeInfo
								.getTbuynumbername());
						parvalueList.add(info);
						// }
					}
					if (choosegemList != null && !choosegemList.isEmpty()
							&& (chargeTypes == null || chargeTypes.isEmpty())) {
						XQTChoosegem choosegem = choosegemList.get(0);
						// for (XQTChoosegem choosegem : choosegemList) {
						info = new XQTParvalueInfo();
						info.setGametype(gametype);
						info.setGametype1(gametype1);
						info.setParvalueId(parInfo.getParvalueId());
						info.setParvalueName(parInfo.getParvalueName());
						info.setProductid(parInfo.getProductid());
						info.setSaleprice(parInfo.getSaleprice());
						info.setProductid1(parInfo.getProductid1());
						info.setSign(parInfo.getSign());
						info.setChoosegemId(choosegem.getId());
						info.setChoosegemName(choosegem.getName());
						parvalueList.add(info);
						// }
					}
					if (chargeTypes != null && !chargeTypes.isEmpty()
							&& choosegemList != null
							&& !choosegemList.isEmpty()) {
						XQTChargetypeInfo chargeTypeInfo = chargeTypes.get(0);
						XQTChoosegem choosegem = choosegemList.get(0);
						info = new XQTParvalueInfo();
						info.setGametype(gametype);
						info.setGametype1(gametype1);
						info.setParvalueId(parInfo.getParvalueId());
						info.setParvalueName(parInfo.getParvalueName());
						info.setProductid(parInfo.getProductid());
						info.setSaleprice(parInfo.getSaleprice());
						info.setProductid1(parInfo.getProductid1());
						info.setSign(parInfo.getSign());
						info.setChargetypeId(chargeTypeInfo.getChargetypeId());
						info.setChargetypeName(chargeTypeInfo
								.getChargetypeName());
						info.setBuynumber_list(chargeTypeInfo
								.getBuynumber_list());
						info.setTbuynumber_list(chargeTypeInfo
								.getTbuynumber_list());
						info.setTbuynumbername(chargeTypeInfo
								.getTbuynumbername());
						info.setChoosegemId(choosegem.getId());
						info.setChoosegemName(choosegem.getName());
						parvalueList.add(info);
					}
					if (chargeTypes == null && choosegemList == null) {
						info = new XQTParvalueInfo();
						info.setGametype(gametype);
						info.setGametype1(gametype1);
						info.setParvalueId(parInfo.getParvalueId());
						info.setParvalueName(parInfo.getParvalueName());
						info.setProductid(parInfo.getProductid());
						parvalueList.add(info);
					}
				}
			}
		}
		return parvalueList;
	}

	/**
	 * 获取充值类型信息
	 * 
	 * @param map
	 * @return
	 */
	public static List<XQTChargetypeInfo> getChargeTypeListFromMap(
			Map<String, List<Object>> map) {
		List<XQTChargetypeInfo> chargeTypeList = new ArrayList<XQTChargetypeInfo>();
		List<Object> gametypes = map.get("gametype");
		List<Object> gametype1s = map.get("gametype1");
		String gametype = null;
		String gametype1 = null;
		if (gametypes != null && !gametypes.isEmpty()) {
			gametype = (String) gametypes.get(0);
		}
		if (gametype1s != null && !gametype1s.isEmpty()) {
			gametype1 = (String) gametype1s.get(0);
		}
		List<Object> chargeTypes = map.get("chargetype_s");
		XQTChargetypeInfo chargeTypeInfo = null;
		if (chargeTypes != null && !chargeTypes.isEmpty()) {
			for (Object obj : chargeTypes) {
				if (obj instanceof XQTChargetypeInfo) {
					chargeTypeInfo = (XQTChargetypeInfo) obj;
					chargeTypeInfo.setGametype(gametype);
					chargeTypeInfo.setGametype1(gametype1);
				}
				chargeTypeList.add(chargeTypeInfo);
			}
		}

		return chargeTypeList;
	}

	/**
	 * 获取账户信息
	 * 
	 * @param map
	 * @return
	 */
	public static List<XQTAccountTypeInfo> getAccountTypeInfoListFromMap(
			Map<String, List<Object>> map) {
		List<XQTAccountTypeInfo> accountTypeList = new ArrayList<XQTAccountTypeInfo>();
		List<Object> gametypes = map.get("gametype");
		List<Object> gametype1s = map.get("gametype1");
		String gametype = null;
		String gametype1 = null;
		if (gametypes != null && !gametypes.isEmpty()) {
			gametype = (String) gametypes.get(0);
		}
		if (gametype1s != null && !gametype1s.isEmpty()) {
			gametype1 = (String) gametype1s.get(0);
		}
		List<Object> accountTypes = map.get("accounttype_s");
		XQTAccountTypeInfo accountTypeInfo = null;
		if (accountTypes != null && !accountTypes.isEmpty()) {
			for (Object obj : accountTypes) {
				if (obj instanceof XQTAccountTypeInfo) {
					accountTypeInfo = (XQTAccountTypeInfo) obj;
					accountTypeInfo.setGametype(gametype);
					accountTypeInfo.setGametype1(gametype1);
				}
				accountTypeList.add(accountTypeInfo);
			}
		}
		return accountTypeList;
	}

	/**
	 * 获取区服信息
	 * 
	 * @param map
	 * @return
	 */
	public static List<XQTGameAreaServerInfo> getAreaServerInfoListFromMap(
			Map<String, List<Object>> map) {
		List<XQTGameAreaServerInfo> areaServerList = new ArrayList<XQTGameAreaServerInfo>();
		List<Object> gametypes = map.get("gametype");
		List<Object> gametype1s = map.get("gametype1");
		String gametype = null;
		String gametype1 = null;
		if (gametypes != null && !gametypes.isEmpty()) {
			gametype = (String) gametypes.get(0);
		}
		if (gametype1s != null && !gametype1s.isEmpty()) {
			gametype1 = (String) gametype1s.get(0);
		}
		List<Object> areaServers = map.get("gamearea_s");
		XQTGameAreaInfo areaInfo = null;
		XQTGameAreaServerInfo areaServerInfo = null;
		if (areaServers != null && !areaServers.isEmpty()) {
			for (Object obj : areaServers) {
				if (obj instanceof XQTGameAreaInfo) {
					areaInfo = (XQTGameAreaInfo) obj;
					List<XQTGameServer> servers = areaInfo.getGameSerList();
					if (servers != null && !servers.isEmpty()) {
						for (XQTGameServer server : servers) {
							areaServerInfo = new XQTGameAreaServerInfo();
							areaServerInfo.setGametype(gametype);
							areaServerInfo.setGametype1(gametype1);
							areaServerInfo.setAreaId(areaInfo.getId());
							areaServerInfo.setAreaName(areaInfo.getName());
							areaServerInfo.setSrvId(server.getId());
							areaServerInfo.setSrvName(server.getName());
							areaServerList.add(areaServerInfo);
						}
					}
					if (servers == null) {
						areaServerInfo = new XQTGameAreaServerInfo();
						areaServerInfo.setGametype(gametype);
						areaServerInfo.setGametype1(gametype1);
						areaServerInfo.setAreaId(areaInfo.getId());
						areaServerInfo.setAreaName(areaInfo.getName());
						areaServerList.add(areaServerInfo);
					}
				}
			}
		}
		return areaServerList;
	}

	/**
	 * 获取文件头部信息
	 * 
	 * @param map
	 * @return
	 */
	public static XQTTopInfo getTopInfoFromMap(Map<String, List<Object>> map) {
		XQTTopInfo topInfo = new XQTTopInfo();
		List<Object> gametypes = map.get("gametype");
		List<Object> gametype1s = map.get("gametype1");
		List<Object> orders = map.get("order");
		List<Object> types = map.get("type");
		List<Object> gamecompanys = map.get("gamecompany");
		String gametype = null;
		String gametype1 = null;
		String order = null;
		String type = null;
		String gamecompany = null;
		if (gametypes != null && !gametypes.isEmpty()) {
			gametype = (String) gametypes.get(0);
			topInfo.setGametype(gametype);
		}
		if (gametype1s != null && !gametype1s.isEmpty()) {
			gametype1 = (String) gametype1s.get(0);
			topInfo.setGametype1(gametype1);
		}
		if (orders != null && !orders.isEmpty()) {
			order = (String) orders.get(0);
			topInfo.setXingOrder(order);
		}
		if (types != null && !types.isEmpty()) {
			type = (String) types.get(0);
			topInfo.setType(type);
		}
		if (gamecompanys != null && !gamecompanys.isEmpty()) {
			gamecompany = (String) gamecompanys.get(0);
			topInfo.setGamecompany(gamecompany);
		}

		return topInfo;
	}
}
